package com.demo2do.fms.admin.entity.search.report;
import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.core.utils.DateUtils;

/**
 *
 * @author Ark
 *
 */
public class HeavyNoLoadInstructionSearch implements QueryBuilder {
	
	// 选择公司	TRANS_CORP_ID
		private Long organizationId;
		//驳运车号（中文）	VEHICLE_NAME
		private String vehicleName;
		//制造商	MANUFACTOR_NAME
		private String manufactorName;
		//重载调度指令组号	FULL_GROUP_NUMBER
		private String fullGroupNumber;
		//空载调度指令组号	EMPTY_GROUP_NUMBER
		private String emptyGroupNumber;
		//重载起始地	FULL_SRC_WH_ID
		private Long fullSrcWhId;
		//重载目的地	FULL_DEST_WH_ID
		private Long fullDestWhId;
		//重载起始地城市	FULL_SRC_CITY_NAME
		private String fullSrcCityName;
		//重载目的地地城市	FULL_DEST_CITY_NAME
		private String fullDestCityName;
		//重载起始地所在省	FULL_SRC_PROV_NAME
		private String fullSrcProvName;
		//重载目的地所在省	FULL_DEST_PROV_NAME
		private String fullDestProvName;
		//重载起运日期	FULL_LEAVING_DATE
		@DateTimeFormat(pattern="yyyy-MM-dd")
		private	String fullStartDate;
		//重载最终日期	FULL_LEAVING_DATE
		@DateTimeFormat(pattern="yyyy-MM-dd")
		private String fullEndDate;
		//空载起始地	EMPTY_SRC_WH_ID
		private Long emptySrcWhId;
		//空载目的地	EMPTY_DEST_WH_ID
		private Long emptyDestWhId;
		//空载起始地城市	EMPTY_SRC_CITY_NAME
		private String emptySrcCityName;
		//空载目的地地城市	EMPTY_DEST_CITY_NAME
		private String emptyDestCityName;
		//空载起始地所在省	EMPTY_SRC_PROV_NAME
		private String emptySrcProvName;
		//空载目的地所在省	EMPTY_DEST_PROV_NAME
		private String emptyDestProvName;
		/*
		 * 
			空载起运日期	EMPTY_LEAVING_DATE
			至	EMPTY_LEAVING_DATE

		 * */
		@DateTimeFormat(pattern="yyyy-MM-dd")
		private String emptyStartDate;
		@DateTimeFormat(pattern="yyyy-MM-dd")
		private String emptyEndDate;

	private QueryOrder queryOrder;
    
    private QueryFilter queryFilter;

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
	 */
	public QueryFilter getPreparedFilter(boolean refresh) {
			Date ssd = DateUtils.parseDate(emptyStartDate, "yyyy-MM-dd");
		   Date sed = DateUtils.parseDate(emptyEndDate, "yyyy-MM-dd");
		   Date lsd = DateUtils.parseDate(fullStartDate, "yyyy-MM-dd");
		   Date led = DateUtils.parseDate(fullEndDate, "yyyy-MM-dd");
		if(queryFilter == null || refresh) {
            queryFilter = new QueryFilter().addDateBetween("shipmentDate", ssd, sed)
											      .addDateBetween("leavingDate", lsd, led)
							      				.addEquals("fullGroupNumber", fullGroupNumber)
												   .addEquals("transCorpId", organizationId)
												   .addLike("manufactorName",manufactorName)
												   .addLike("vehicleName", vehicleName)
												   .addEquals("emptyGroupNumber", emptyGroupNumber)
												   .addEquals("fullSrcWhId", fullSrcWhId)
												   .addEquals("fullDestWhId", fullDestWhId)
												   .addLike("fullSrcCityName",fullSrcCityName)
												   .addLike("fullDestCityName",fullDestCityName)
												   .addLike("fullSrcProvName",fullSrcProvName)
												   .addLike("fullDestProvName",fullDestProvName)
												   .addEquals("emptySrcWhId",emptySrcWhId)
												   .addEquals("emptyDestWhId",emptyDestWhId)
												   .addLike("emptySrcCityName",emptySrcCityName)
												   .addEquals("emptyDestCityName", emptyDestCityName)
												   .addLike("emptySrcProvName", emptySrcProvName)
												   .addLike("emptyDestProvName", emptyDestProvName)
												  ;
        }
        
        return queryFilter;
	}

	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
	 */
	public String buildSentenceTemplate() {		
		
		String sentence = "FROM HeavyNoLoadInstruction "+getPreparedFilter(false).whereSentence();
        return sentence;
	}

	/* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
	 */
	public QueryOrder getOrder() {
		return queryOrder;
	}

	public Long getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(Long organizationId) {
		this.organizationId = organizationId;
	}

	public String getVehicleName() {
		return vehicleName;
	}

	public void setVehicleName(String vehicleName) {
		this.vehicleName = vehicleName;
	}

	public String getManufactorName() {
		return manufactorName;
	}

	public void setManufactorName(String manufactorName) {
		this.manufactorName = manufactorName;
	}
	public String getFullGroupNumber() {
		return fullGroupNumber;
	}

	public void setFullGroupNumber(String fullGroupNumber) {
		this.fullGroupNumber = fullGroupNumber;
	}

	public String getEmptyGroupNumber() {
		return emptyGroupNumber;
	}

	public void setEmptyGroupNumber(String emptyGroupNumber) {
		this.emptyGroupNumber = emptyGroupNumber;
	}

	public Long getFullSrcWhId() {
		return fullSrcWhId;
	}

	public void setFullSrcWhId(Long fullSrcWhId) {
		this.fullSrcWhId = fullSrcWhId;
	}

	public Long getFullDestWhId() {
		return fullDestWhId;
	}

	public void setFullDestWhId(Long fullDestWhId) {
		this.fullDestWhId = fullDestWhId;
	}

	public String getFullSrcCityName() {
		return fullSrcCityName;
	}

	public void setFullSrcCityName(String fullSrcCityName) {
		this.fullSrcCityName = fullSrcCityName;
	}

	public String getFullDestCityName() {
		return fullDestCityName;
	}

	public void setFullDestCityName(String fullDestCityName) {
		this.fullDestCityName = fullDestCityName;
	}

	public String getFullSrcProvName() {
		return fullSrcProvName;
	}

	public void setFullSrcProvName(String fullSrcProvName) {
		this.fullSrcProvName = fullSrcProvName;
	}

	public String getFullDestProvName() {
		return fullDestProvName;
	}

	public void setFullDestProvName(String fullDestProvName) {
		this.fullDestProvName = fullDestProvName;
	}

	public String getFullStartDate() {
		return fullStartDate;
	}

	public void setFullStartDate(String fullStartDate) {
		this.fullStartDate = fullStartDate;
	}

	public String getFullEndDate() {
		return fullEndDate;
	}

	public void setFullEndDate(String fullEndDate) {
		this.fullEndDate = fullEndDate;
	}

	public Long getEmptySrcWhId() {
		return emptySrcWhId;
	}

	public void setEmptySrcWhId(Long emptySrcWhId) {
		this.emptySrcWhId = emptySrcWhId;
	}

	public Long getEmptyDestWhId() {
		return emptyDestWhId;
	}

	public void setEmptyDestWhId(Long emptyDestWhId) {
		this.emptyDestWhId = emptyDestWhId;
	}

	public String getEmptySrcCityName() {
		return emptySrcCityName;
	}

	public void setEmptySrcCityName(String emptySrcCityName) {
		this.emptySrcCityName = emptySrcCityName;
	}

	public String getEmptyDestCityName() {
		return emptyDestCityName;
	}

	public void setEmptyDestCityName(String emptyDestCityName) {
		this.emptyDestCityName = emptyDestCityName;
	}

	public String getEmptySrcProvName() {
		return emptySrcProvName;
	}

	public void setEmptySrcProvName(String emptySrcProvName) {
		this.emptySrcProvName = emptySrcProvName;
	}

	public String getEmptyDestProvName() {
		return emptyDestProvName;
	}

	public void setEmptyDestProvName(String emptyDestProvName) {
		this.emptyDestProvName = emptyDestProvName;
	}

	public String getEmptyStartDate() {
		return emptyStartDate;
	}

	public void setEmptyStartDate(String emptyStartDate) {
		this.emptyStartDate = emptyStartDate;
	}

	public String getEmptyEndDate() {
		return emptyEndDate;
	}

	public void setEmptyEndDate(String emptyEndDate) {
		this.emptyEndDate = emptyEndDate;
	}
	
	
	
}
